package org.wang.generalcode.modules.exam.controller;

import com.baomidou.mybatisplus.core.metadata.IPage;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.validation.Valid;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.*;
import org.wang.generalcode.modules.exam.pojo.entity.TestPaperQuestionInfoEntity;
import org.wang.generalcode.modules.exam.pojo.param.TestPaperQuestionInfoParams;
import org.wang.generalcode.modules.exam.pojo.vo.TestPaperQuestionInfoVO;
import org.wang.generalcode.modules.exam.service.TestPaperQuestionInfoService;
import org.wang.generalcode.support.mybaties.Condition;
import org.wang.generalcode.support.mybaties.Query;
import org.wang.generalcode.support.result.PageResult;
import org.wang.generalcode.support.result.Result;
import org.wang.generalcode.support.utils.Func;

import java.util.List;

/**
 * 试卷试题关联表前端控制层
 *
 * @author wz
 * @since 2024-11-29
 */
@Tag(name = "试卷试题关联表接口")
@RestController
@RequestMapping("exam/test_paper_question_info")
@RequiredArgsConstructor
public class TestPaperQuestionInfoController {

    private final TestPaperQuestionInfoService testpaperquestioninfoService;

    @Operation(summary = "试卷试题关联表分页列表")
    @GetMapping("/page")
    public PageResult<TestPaperQuestionInfoVO> getTestPaperQuestionInfoPage(TestPaperQuestionInfoParams queryParams, Query query) {
        IPage<TestPaperQuestionInfoVO> result = testpaperquestioninfoService.getTestPaperQuestionInfoPage(Condition.getPage(query),queryParams);
        return PageResult.success(result);
    }

    @Operation(summary = "新增试卷试题关联表")
    @PostMapping("/save")
    public Result saveTestPaperQuestionInfo(@RequestBody @Valid List<TestPaperQuestionInfoEntity> formData) {
        boolean result = testpaperquestioninfoService.saveBatch(formData);
        return Result.judge(result);
    }

    @Operation(summary = "获取试卷试题关联表表单数据")
    @GetMapping("/detail")
    public Result<TestPaperQuestionInfoEntity> getTestPaperQuestionInfoForm(
        @Parameter(name = "主键", required = true) @RequestParam Long id
    ) {
            TestPaperQuestionInfoEntity formData = testpaperquestioninfoService.getById(id);
        return Result.success(formData);
    }

    @Operation(summary = "修改试卷试题关联表")
    @PutMapping(value = "/update")
    public Result updateTestPaperQuestionInfo(
            @RequestBody TestPaperQuestionInfoEntity entity
    ) {
        boolean result = testpaperquestioninfoService.updateById(entity);
        return Result.judge(result);
    }

    @Operation(summary = "删除试卷试题关联表")
    @DeleteMapping("/remove")
    public Result deleteTestPaperQuestionInfos(
            @Parameter(name = "主键集合", required = true) @RequestParam String ids
    ) {
        boolean result = testpaperquestioninfoService.removeBatchByIds(Func.toLongList(ids));
        return Result.judge(result);
    }
}
